package com.epalmpay.controller.shop.activity;

import java.util.List;

import javax.annotation.Resource;

import com.epalmpay.dto.activity.*;
import com.epalmpay.service.activity.IActivityBaseService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.epalmpay.commom.BaseController;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.entity.Page;
import com.epalmpay.service.activity.IActivityCouponService;
import com.epalmpay.util.Tools;

@Controller
@RequestMapping(value="/shop/activity")
public class ActivityController extends BaseController {
     
	@Resource
	private IActivityCouponService activityCouponService;

	@Resource
	private IActivityBaseService activityBaseService;

	/**
	 * 显示优惠券分页列表
	 * 
	 */
	@RequestMapping(value="/couponList")
	@ResponseBody
	public CouponListOutDTO  couponList(CouponInDTO couponInDTO,PageDTO pageDTO){
		CouponListOutDTO couponListOutDTO=new CouponListOutDTO();
		try {
			Page page=Tools.pageEmtity(pageDTO);
			
            //查询时取数据			
			if(couponInDTO.getIsReload()){
				//获取优惠券列表信息
				List<CouponOutDTO> couponOutDTOList = activityCouponService.
						getCouponListByShopId(couponInDTO, page);
				couponListOutDTO.setCouponOutDTOList(couponOutDTOList);
			}
			couponListOutDTO.setPage(page); 
			couponListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return couponListOutDTO;
		} catch (ApplicationException ae) { 
			couponListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		 catch (Exception e) { 
			 couponListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return couponListOutDTO;
	}
	/**
	 * 显示优惠券分页列表
	 *
	 */
	@RequestMapping(value="/list")
	@ResponseBody
	public ActivityBaseListOutDTO list(ActivityBaseInDTO activityBaseInDTO, PageDTO pageDTO){
		ActivityBaseListOutDTO activityBaseListOutDTO=new ActivityBaseListOutDTO();
		try {
			Page page=Tools.pageEmtity(pageDTO);

            //查询时取数据
			if(activityBaseInDTO.getIsReload()){
				activityBaseListOutDTO= activityBaseService.queryActivityList(activityBaseInDTO, page);
			}
			activityBaseListOutDTO.setPage(page);
			activityBaseListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return activityBaseListOutDTO;
		} catch (ApplicationException ae) {
			activityBaseListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
			logger.error(ae);
		}
		 catch (Exception e) {
			 activityBaseListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
			logger.error(e);
		}
		return activityBaseListOutDTO;
	}

	
}
